package com.huadi.firematerialident.dao;

import com.huadi.firematerialident.po.Review;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class ReviewDaoImpl implements ReviewDao{

    @Autowired
    JdbcTemplate jdbcTemplate;

    public int addReview(Review review) {
        String sql="insert into Review values(?,?,?,now(),?,?,0,now())";
        return jdbcTemplate.update(sql,
                review.getReviewID(),
                review.getApsID(),
                review.getRevID(),
                review.getRevConclusion(),
                review.getArchivingStatus());
    }

    public int deleteReviewByID(String reviewID) {
        String sql="update review set LogicalAddDel=0,LastModification=now() where ReviewID=?";
        return jdbcTemplate.update(sql,reviewID);
    }


    public int updateReview(Review review) {
        String sql="update review set ReviewID=?,ApsID=?,RevTime=?," +
                "RevConclusion=?,ArchivingStatus=?,LogicalAddDel=1,LastModification=now() where ReviewID=?";
        return jdbcTemplate.update(sql,review.getReviewID(),
                review.getReviewID(),
                review.getApsID(),
                review.getRevTime(),
                review.getRevConclusion(),
                review.getArchivingStatus());
    }


    public List<Map<String,Object>> selectReviewByID(String reviewID) {
        String sql = "select * from review where ReviewID = ?";
        return jdbcTemplate.queryForList(sql,reviewID);
    }



    public List<Map<String,Object>> getAllReview() {
        String sql="select * from review";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public List<Map<String, Object>> selectReviewByID1(String ApsID) {
        String sql="select * from review where ApsID = ?";
        return jdbcTemplate.queryForList(sql,ApsID);
    }
}












